use "$data/demog_meta.dta", clear

drop if as_of<2010
egen p999=pctile(rate_spread), p(99.9)
keep if rate_spread<p999

keep if loan_amount>=50

by as_of, sort: egen five_less=count(rate_spread) if rate_spread>=5&rate_spread<5.75
by as_of, sort: egen six_less=count(rate_spread) if rate_spread>5.75&rate_spread<=6.5
by as_of, sort: egen six_more=count(rate_spread) if rate_spread>6.5



collapse (mean) five_less six_less six_more, by(as_of_year)
gen sum_all=five_less+six_less+six_more
drop if as_of==.
twoway conn sum_all as_of_year if as_of>=2010, msymbol(T)/*
*/ xline(2013.5)  legend(label(1 "5 to 5.75"))/*
*/ ytitle(Number of Mortgages with Rate Spread > 5)  graphregion(color(white)) bgcolor(white) xtitle(Year)

graph export "$figures/freq_over_time_more50_sum.eps", as(eps) preview(on) replace


use "$data/demog_meta.dta", clear

drop if as_of<2010
egen p999=pctile(rate_spread), p(99.9)
keep if rate_spread<p999

keep if loan_amount<50
by as_of, sort: egen seven_less=count(rate_spread) if rate_spread>=7&rate_spread<7.75
by as_of, sort: egen eight_less=count(rate_spread) if rate_spread>7.75&rate_spread<=8.5
by as_of, sort: egen eight_more=count(rate_spread) if rate_spread>8.5

collapse (mean) seven_less eight_less eight_more, by(as_of_year)
gen sum_all=seven_less+eight_less+eight_more
drop if as_of==.
twoway conn sum_all as_of_year if as_of>=2010, msymbol(T)/*
*/  xline(2013.5)  legend(label(1 "7 to 7.75"))/*
*/ ytitle(Number of Mortgages with Rate Spread > 7) xtitle(Year) graphregion(color(white)) bgcolor(white)
graph export "$figures/freq_over_time_less50_sum.eps", as(eps) preview(on) replace

